import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import tableRouter from './modules/table'
/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/authRedirect',
    component: () => import('@/views/login/authRedirect.vue'),
    hidden: true
  },
  {
    path: '/register',
    component: () => import('@/views/register/index'),
    hidden: true
  },
  {
    path: '/uploadQualifications',
    component: () => import('@/views/uploadQualifications/index'),
    hidden: true
  },
  {
    path: '/merchantRegistration',
    component: () => import('@/views/uploadQualifications/merchantRegistration'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },

  {
    path: '/profile',
    component: Layout,
    redirect: '/profile/index',
    hidden: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/profile/index'),
        name: 'Profile',
        meta: { title: 'Profile', icon: 'user', noCache: true }
      }
    ]
  }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  /** when your routing map is too long, you can split it into small modules **/
// componentsRouter,
 
  {
    path: '/',
    component: Layout,
    redirect: '/storeInformation',
    name: 'StoreInformation',
  hidden: false, // 不在侧边栏显
  meta: { title: '店家门店', icon: 'dashboard',},
    children: [
      {
        path: 'StoreInformation',
        component: () => import('@/views/storeInformation/index'),
        name: 'Dashboard', // 是否显示在菜单
        meta: { title: '店家门店', icon: 'dashboard', noCache: true },
        // hidden: true // 是否显示在菜单
      },
      {
        path: 'info',
        component: () => import('@/views/storeInformation/info'),
        name: 'StoreInformation/info',
        meta: { title: '店家配置', icon: 'dashboard', noCache: true ,},
        hidden: true // 是否显示在菜单
      },
      
    ]
  },
  {
    path: '/dashboard',
    component: Layout,
    // redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: '优惠卷', icon: 'dashboard', affix: true }
      }
    ]
  },
  {
    path: '/staff',
    component: Layout,
    redirect: '/staff',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/staff/index'),
        name: 'Dashboard',
        meta: { title: '员工档案', icon: 'dashboard', affix: true }
      }
    ]
  },

  {
    path: '/lockDevice',
    component: Layout,
    redirect: '/lockDevice',
    name: 'Example',
    meta: {
      title: 'Example',
      icon: 'el-icon-s-help'
    },
    children:[
        {
            path: 'LockDevice',
            component: () => import('@/views/lockDevice/index.vue'),
            name: 'LockDevice',
            meta: { title: '锁设备', noCache: true }
         }
         
    ]
    
  },
  {
    path: '/smartDevices',
    component: Layout,
    redirect: '/smartDevices',
    children: [
      {
        path: 'SmartDevices',
        component: () => import('@/views/smartDevices/index'),
        name: 'Dashboard',
        meta: { title: '智能设备', icon: 'dashboard', affix: true }
      }
    ]
  },
  {
    path: '/rechargeRules',
    component: Layout,
    redirect: '/rechargeRules',
    children: [
      {
        path: 'RechargeRules',
        component: () => import('@/views/rechargeRules/index'),
        name: 'Dashboard',
        meta: { title: '充值规则档案', icon: 'dashboard', affix: true }
      }
    ]
  },
  tableRouter,
  {
    path: '/withdrawal',
    component: Layout,
    redirect: 'withdrawal',
    name: 'withdrawal',
    meta: {
      title: '审核页',
      icon: '404'
    },
    children: [
      {
        path: 'withdrawal',
        component: () => import('@/views/withdrawal/index.vue'),
        name: 'Page401',
        meta: { title: '审核', noCache: true }
      },
      {
        path: '/withdrawal/details',
        component: () => import('@/views/withdrawal/details.vue'),
        name: 'Page401',
        meta: { title: '审核详情', noCache: true },
        hidden: true // 是否显示在菜单
      },
      {
        path: '/withdrawal/withdrawalDetail',
        component: () => import('@/views/withdrawal/withdrawalDetail.vue'),
        name: 'Page401',
        meta: { title: '提现审核详情', noCache: true },
        hidden: true // 是否显示在菜单
      },
    ]
  },
  {
    path: '/error',
    component: Layout,
    redirect: 'noRedirect',
    name: 'ErrorPages',
    meta: {
      title: 'Error Pages',
      icon: '404'
    },
    children: [
      {
        path: '401',
        component: () => import('@/views/error-page/401'),
        name: 'Page401',
        meta: { title: '401', noCache: true }
      },
      {
        path: '404',
        component: () => import('@/views/error-page/404'),
        name: 'Page404',
        meta: { title: '404', noCache: true }
      }
    ]
  },
  {
    path: '/excel',
    component: Layout,
    redirect: '/excel/export-excel',
    name: 'Excel',
    meta: {
      title: 'Excel',
      icon: 'excel'
    },
    children: [
      {
        path: 'export-excel',
        component: () => import('@/views/excel/export-excel'),
        name: 'ExportExcel',
        meta: { title: 'Export Excel' }
      },
      {
        path: 'export-selected-excel',
        component: () => import('@/views/excel/select-excel'),
        name: 'SelectExcel',
        meta: { title: 'Export Selected' }
      },
      {
        path: 'export-merge-header',
        component: () => import('@/views/excel/merge-header'),
        name: 'MergeHeader',
        meta: { title: 'Merge Header' }
      },
      {
        path: 'upload-excel',
        component: () => import('@/views/excel/upload-excel'),
        name: 'UploadExcel',
        meta: { title: 'Upload Excel' }
      }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]
const createRouter = () => new Router({
  mode: 'hash', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})
const router = createRouter()
// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}
export default router
